//
//  XKMineBankCarCell.m
//  XKJY
//
//  Created by xuyaguang on 2017/1/14.
//  Copyright © 2017年 xiaokang100. All rights reserved.
//

#import "XKMineBankCarCell.h"


@interface XKMineBankCarCell ()

@property (nonatomic, strong) UIImageView *cardBgImageView;     // 背景
@property (nonatomic, strong) UIImageView *cardIconImageView;   // 图标
@property (nonatomic, strong) UIImageView *cardIconBgImageView; // 图标白背景
@property (nonatomic, strong) UIImageView *cardMarkImageVIew;   // 快捷支付
@property (nonatomic, strong) UILabel     *cardNumberLabel;     // 银行卡号码
@property (nonatomic, strong) UILabel     *cardNameLabel;       // 开户银行名
@property (nonatomic, strong) UILabel     *cardTypeLabel;       // 储蓄卡

@end
@implementation XKMineBankCarCell

#pragma mark - 自定义cell重写构造方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self configArguments];// 设置自身
        [self createSubviews]; // 创建并添加
    }
    return self;
}

#pragma mark - 设置自身
- (void)configArguments {
    self.backgroundColor = kBaseGrayColor;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
}



#pragma mark - 创建控件
- (void)createSubviews {
    
    _cardBgImageView = [UIImageView new];
    _cardBgImageView.image = [UIImage imageNamed:@"mybank_con_bg_blu"];
    _cardBgImageView.layer.cornerRadius = 6;
    _cardBgImageView.layer.masksToBounds = YES;
    
    _cardIconImageView = [UIImageView new];
    _cardIconImageView.image = [UIImage imageWithColor:WhiteColor];
    _cardIconImageView.layer.cornerRadius = 20*Scale_W;
    _cardIconImageView.layer.masksToBounds = YES;
    
    _cardIconBgImageView = [UIImageView new];
    _cardIconBgImageView.image = [UIImage imageWithColor:WhiteColor];
    _cardIconBgImageView.layer.cornerRadius = 25*Scale_W;
    _cardIconBgImageView.layer.masksToBounds = YES;
    
    
    _cardMarkImageVIew = [UIImageView new];
    _cardMarkImageVIew.image = [UIImage imageNamed:@"mybank_icon_kjzf"];
    
    _cardNumberLabel = [UILabel getLabWithText:@"**** **** **** ****" textFont:Font_15 textColor:WhiteColor textAlignment:NSTextAlignmentLeft];
    
    _cardNameLabel = [UILabel getLabWithText:@"----" textFont:Font_13 textColor:WhiteColor textAlignment:NSTextAlignmentLeft];
    
//    _cardTypeLabel = [UILabel getLabWithText:@"储蓄卡" textFont:Font_10 textColor:WhiteColor textAlignment:NSTextAlignmentLeft];
    
    [self.contentView addSubview:self.cardBgImageView];
    [self.contentView addSubview:self.cardIconBgImageView];
    [self.contentView addSubview:self.cardIconImageView];
    [self.contentView addSubview:self.cardNameLabel];
    [self.contentView addSubview:self.cardMarkImageVIew];
    [self.contentView addSubview:self.cardNumberLabel];
//    [self.contentView addSubview:self.cardTypeLabel];
    
    // 在添加子控件之后再添加约束
    [self addConstraints];
}
#pragma mark - 添加约束
- (void)addConstraints {
    
    
    [self.cardBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(0*Scale_H);
        make.left.mas_equalTo(self.contentView).offset(10*Scale_W);
        make.right.mas_equalTo(self.contentView).offset(-10*Scale_W);
        make.height.mas_equalTo(106*Scale_H);
        make.bottom.mas_equalTo(self.contentView).offset(-0*Scale_H).priorityHigh();
    }];
    
    [self.cardIconBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(self.cardBgImageView).offset(15*Scale_W);
        make.size.mas_equalTo(CGSizeMake(50*Scale_W, 50*Scale_W));
    }];
    
    [self.cardIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.mas_equalTo(self.cardIconBgImageView);
        make.size.mas_equalTo(CGSizeMake(40*Scale_W, 40*Scale_W));
    }];
    
    [self.cardNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.cardIconImageView.mas_right).offset(10*Scale_W);
        make.top.mas_equalTo(self.cardIconImageView);
    }];
    
//    [self.cardTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(self.cardNameLabel);
//        make.top.mas_equalTo(self.cardNameLabel.mas_bottom).offset(5*Scale_H);
//    }];
    
    [self.cardMarkImageVIew mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.cardBgImageView).offset(20*Scale_W);
        make.right.mas_equalTo(self.cardBgImageView).offset(-20*Scale_W);
        make.size.mas_equalTo(CGSizeMake(51*Scale_W, 13*Scale_W));
    }];
    
    [self.cardNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.cardNameLabel);
        make.bottom.mas_equalTo(self.cardBgImageView).offset(-15*Scale_H);
    }];
}


- (void)setBankCardDataModel:(XKBankDataModel *)bankCardDataModel {
    _bankCardDataModel = bankCardDataModel;
    
    _cardNameLabel.text = bankCardDataModel.bankname;
    _cardNumberLabel.text = [NSString getSecrectStringWithBankCardNumber:bankCardDataModel.cardnum];

    //路径
    NSString *path = [[NSBundle mainBundle] pathForResource:@"bankcard"ofType:@"plist"];
    //读取
    NSArray *cardArray = [NSArray arrayWithContentsOfFile:path];
    for (NSDictionary *dict in cardArray) {
        if ([dict[@"bank_card_name"] isEqualToString:bankCardDataModel.bankname]) {
            _cardIconImageView.image = [UIImage imageNamed:dict[@"bank_card_icon"]];
            _cardBgImageView.image = [UIImage imageNamed:dict[@"bank_card_background"]];
            break;
        }
    }
    
}


@end
